package cn.iocoder.yudao.module.infrastructure.dict.controller.app;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infrastructure.dict.controller.app.vo.AppDictTypeSimpleRespVO;
import cn.iocoder.yudao.module.infrastructure.dict.dal.dataobject.DictTypeDO;
import cn.iocoder.yudao.module.infrastructure.dict.dal.mysql.DictTypeMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 字典类型") // FIXME 新增
@RestController("patchAppDictTypeController")
@RequestMapping("/system/dict-type")
@Validated
public class AppDictTypeController {
    @Resource
    private DictTypeMapper dictTypeMapper;

    @GetMapping(value = {"simple-list"})
    @Operation(summary = "获得全部字典类型列表", description = "只包括启用的字典类型，主要用于前端的下拉选项")
    @PermitAll // 无需添加权限认证，因为前端全局都需要
    public CommonResult<List<AppDictTypeSimpleRespVO>> getSimpleDictTypeList() {
        List<DictTypeDO> list = dictTypeMapper.selectList("status", CommonStatusEnum.ENABLE.getStatus());
        return success(BeanUtils.toBean(list, AppDictTypeSimpleRespVO.class));
    }

}
